<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>水平垂直居中</title>
    <style type="text/css">

        .test-div {
            border: 1px solid #0ac2d2;
            position: absolute;
        }

        .absolute-center {
            margin: auto;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            height: 150px;
            width: 200px;
        }

        .absolute-center2 {
            width: 400px;
            height: 200px;
            left: 50%;
            top: 50%;
            margin-left: -200px;
            margin-top: -100px;
        }
    </style>
</head>
<body>
<h2>方法1:绝对定位水平垂直居中</h2>
<div class="test-div absolute-center">
    我是方法1的水平垂直居中div
</div>

<h2>方法2:绝对定位水平垂直居中</h2>
<div class="test-div absolute-center2">我是方法2的水平垂直居中div</div>


</body>
</html>